//
//  CZHomeViewController.swift
//  weibo
//
//  Created by Mac on 16/5/9.
//  Copyright © 2016年 fengzhixiang. All rights reserved.
//

import UIKit

class CZHomeViewController: CZBaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        setupNavigationBar()

    }

    //设置导航栏
    private func setupNavigationBar(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_friendsearch", target:self, action: "didClickFriendsearch")

        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop", target: self, action: "didClickPop")


        //设置首页的titleView
        let button = CZHomeTitleButton()
        button.setTitle("用户名称", forState: UIControlState.Normal)

        button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setImage(UIImage(named: "navigationbar_arrow_down"), forState: UIControlState.Normal)
        button.addTarget(self, action: "didClickTitleView:", forControlEvents: UIControlEvents.TouchUpInside)
        button.sizeToFit()

        navigationItem.titleView = button


    }


    func didClickTitleView(button: UIButton){
        //1.修改按钮的状态
        button.selected = !button.selected

        //2.旋转图片(CGAffineTransformIdentity 可以还原)
        UIView.animateWithDuration(0.25) { () -> Void in
            let transfrom = button.selected ? CGAffineTransformMakeRotation(CGFloat(M_PI - 0.001)) : CGAffineTransformIdentity
            button.imageView?.transform = transfrom
        }


    }

    func didClickFriendsearch(){
        CZPrint(items: "点击了坐边按钮")
    }

    func didClickPop(){
        CZPrint(items: "点击了右边按钮")
    }


}
